﻿using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using Gameplay.PVE;
using Gameplay.PVE.Utils;
using UnityEngine;
using Yoozoo.Gta.Common;

public class PveSkillDisplayController : MonoBehaviour
{
    // Start is called before the first frame update

    // Update is called once per frame
    //void Update()
    //{
        
    //}

    public void CallLuaFunction()
    {
        
    }
    
    
    public void StartBlackScreen(string param)
    {
        float blackPercent = 1;
        float blackTime = 0.01f;
        var p = param.Split(';');
        if (p.Length > 1)
        {
            float.TryParse(p[0], out blackPercent);
            float.TryParse(p[1], out blackTime);
        }
        //PveManager.Instance.ShowSkillBlackScreen(blackPercent,blackTime);
        ResidentHandler.Inst.GetFunction("L_RpgManager.StartSkillBlackScreen").Action(blackPercent,blackTime);
    }

    public void EndBlackScreen(string param)
    {
        //PveManager.Instance.HideSkillBlackScreen();
        ResidentHandler.Inst.GetFunction("L_RpgManager.EndSkillBlackScreen").Action(0);
    }

    public void ChangeTimeScale(string param)
    {
        float startTimeScale = 1;
        float endTimeScale = 1;
        float duration = 0;
        var p = param.Split(';');
        if (p.Length > 2)
        {
            float.TryParse(p[0], out startTimeScale);
            float.TryParse(p[1], out endTimeScale);
            float.TryParse(p[2], out duration);
            /*Time.timeScale = startTimeScale * TimeManager.gameTimeScale;
            TimeManager.Instance.DelayCall((int) (duration * 1000), () => { Time.timeScale = endTimeScale; },true);*/
            ResidentHandler.Inst.GetFunction("L_RpgManager.ChangeTimeScale").Action(startTimeScale,endTimeScale,duration);
        }
    }
    
    public void ChangeSkillTimeScale(string param)
    {
        float startTimeScale = 1;
        float endTimeScale = 1;
        float duration = 0;
        var p = param.Split(';');
        if (p.Length > 2)
        {
            float.TryParse(p[0], out startTimeScale);
            float.TryParse(p[1], out endTimeScale);
            float.TryParse(p[2], out duration);
            /*Time.timeScale = startTimeScale * TimeManager.gameTimeScale;
            TimeManager.Instance.DelayCall((int) (duration * 1000), () => { Time.timeScale = endTimeScale; },true);*/
            ResidentHandler.Inst.GetFunction("L_RpgManager.ChangeSkillTimeScale").Action(startTimeScale,endTimeScale,duration);
        }
    }


    public void LookAtEnemy()
    {
        ResidentHandler.Inst.GetFunction("L_RpgManager.LookAtEnemy").Action(0);
    }
    
    public void Pause()
    {
        //PveManager.Instance.StartSkillPause();
        ResidentHandler.Inst.GetFunction("L_RpgManager.SkillPause").Action(0);
    }

    public void Resume()
    {
        //PveManager.Instance.EndSkillPause();
        ResidentHandler.Inst.GetFunction("L_RpgManager.SkillResume").Action(0);
    }

    public void ShowHud()
    {
        //PveManager.Instance.ShowAllHud();
        ResidentHandler.Inst.GetFunction("L_RpgManager.SetHudAndFlyTextVisible").Action(true);
    }

    public void HideHud()
    {
        //PveManager.Instance.HideAllHud();
        ResidentHandler.Inst.GetFunction("L_RpgManager.SetHudAndFlyTextVisible").Action(false);
    }

    public void SkillEnd(string param)
    {
        var style = CinemachineBlendDefinition.Style.Cut;
        float time = 0;
        var p = param.Split(';');
        if (p.Length > 1)
        {
            int.TryParse(p[0], out int s);
            style = (CinemachineBlendDefinition.Style)s;
            float.TryParse(p[1], out var t);
            time = t;
        }
        ResidentHandler.Inst.GetFunction("L_RpgManager.SkillCameraEnd").Action((int)style,time);
        //PveCameraManager.Instance.SkillEnd(style,time);
    }
    
    public void SkillStart(string param)
    {
        var style = CinemachineBlendDefinition.Style.Cut;
        float time = 0;
        var p = param.Split(';');
        if (p.Length > 1)
        {
            int.TryParse(p[0], out int s);
            style = (CinemachineBlendDefinition.Style)s;
            float.TryParse(p[1], out var t);
            time = t;
        }
        //PveCameraManager.Instance.SkillStart(style,time);
        ResidentHandler.Inst.GetFunction("L_RpgManager.SkillCameraStart").Action((int)style,time);
    }

    public void SwitchCamera(string param)
    {
        var style = CinemachineBlendDefinition.Style.Cut;
        float time = 0;
        int cameraIndex = 0;
        int followTargetType = 0; 
        var p = param.Split(';');
        if (p.Length > 3)
        {
            int.TryParse(p[0], out int c);
            cameraIndex = c;
            int.TryParse(p[1], out int ftt);
            followTargetType = ftt;
            int.TryParse(p[2], out int s);
            style = (CinemachineBlendDefinition.Style)s;
            float.TryParse(p[3], out var t);
            time = t;
        }
        //PveCameraManager.Instance.SkillStart(style,time);
        ResidentHandler.Inst.GetFunction("L_RpgManager.SwitchSkillCamera").Action(cameraIndex,followTargetType,(int)style,time);
    }

    public void HideOthers()
    {
        ResidentHandler.Inst.GetFunction("L_RpgManager.HideOthers").Action(0);
    }

    public void ShowOthers()
    {
        ResidentHandler.Inst.GetFunction("L_RpgManager.ShowOthers").Action(0);
    }
}
